package com.zhangruile.dao;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;

/**
 * ClassName: BaseDao
 *
 * @author :张蕊乐
 *         version :
 * @since JDK 1.8
 * date: 2017 11 09 19:56
 */
public class BaseDao {
    private static final String DB_URL="jdbc:mysql://127.0.0.1:3306/train?characterEncoding=utf8";
    private static final String DB_USER_NAME="root";
    private static final String DB_PASSWORD="root";
    private static final String DB_DRIVER_CLASS_NAME="com.mysql.jdbc.Driver";
    private DataSource dataSource=null;
    /**
     * 创建连接池
     * @return
     */
    protected DataSource getDataSource(){
        if(dataSource!=null){
            return dataSource;
        }
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setUrl(DB_URL);
        dataSource.setUsername(DB_USER_NAME);
        dataSource.setPassword(DB_PASSWORD);
        dataSource.setDriverClassName(DB_DRIVER_CLASS_NAME);
        this.dataSource=dataSource;
        return dataSource;
    }

}
